package cn.com.xy.sms.sdk.service.cardservice;

import org.json.JSONObject;

import cn.com.xy.sms.sdk.constant.Constant;
import cn.com.xy.sms.sdk.log.LogManager;
import cn.com.xy.sms.sdk.net.NetUtil;
import cn.com.xy.sms.sdk.net.NetWebUtil;
import cn.com.xy.sms.sdk.util.KeyManager;
import cn.com.xy.sms.sdk.util.StringUtils;
import cn.com.xy.sms.sdk.util.XyUtil;
import cn.com.xy.sms.util.SdkCallBack;

/**
 * Created by chenrong on 2016/11/17.
 */
/* SDK-682 chenrong 20161121 start*/
public class CardService {

    /**
     * 根据电影名称获取电影海报URL
     *
     * @param movieName 电影名称
     * @param callBack  index(0)为"0"请求成功,
     *                 index(1)成功返回数据格式：
     *                 { "status": "1",
     *                  "desc": "成功",
     *                  "body": {
     *                     imgUrl:”http://192.168.x.x/xx.png”
     *                   }
     *                 }
     */
    public static void queryMoviePosters(String movieName, final SdkCallBack callBack) {
        if (StringUtils.isNull(movieName)) {
            XyUtil.doXycallBackResult(callBack);
            return;
        }
        JSONObject requestJson = new JSONObject();
        try {
            requestJson.put("movieName", movieName);
            requestJson.put("sdkVersion", NetUtil.APPVERSION);
            requestJson.put("channel", KeyManager.getAppKey());
            NetWebUtil.sendPostRequest(NetWebUtil.WEB_SERVER_URL_MOVIE_POSTERS, requestJson.toString(), callBack);
        } catch (Throwable e) {

            LogManager.e(Constant.TAG, "queryMoviePosters : ", e);

            XyUtil.doXycallBackResult(callBack);
        }
    }

    /**
     * 根据城市和情景号获取发现数据
     *
     * @param city     城市名
     * @param sceneId  情景ID
     * @param version  当前发现数据版本号
     * @param callBack  index(0)为"0"请求成功
     *                 index(1)成功返回数据格式：
     *                 {"status": "1",
     *                 "desc": "成功",
     *                 "version": "14779893701477904120",
     *                 "body": [{"imgUrl": "xxx.xxx.png","btnName": "精选酒店",
     *                 actionData":{
     *                 "type":"WEB_URL","url":"http://192.xx.xxx.xxx/xad/xx.html"
     *                 }
     *                 }
     *                 ]}
     */
    public static void queryDiscoverData(String city, String sceneId, String version, final SdkCallBack callBack) {
        if (StringUtils.isNull(sceneId)) {
            XyUtil.doXycallBackResult(callBack);
            return;
        }

        JSONObject requestJson = new JSONObject();
        try {
            requestJson.put("city", city); //
            requestJson.put("sceneId", sceneId);
            requestJson.put("sdkVersion", NetUtil.APPVERSION);
            requestJson.put("channel", KeyManager.getAppKey());
            requestJson.put("version", version);
            NetWebUtil.sendPostRequest(NetWebUtil.WEB_SERVER_URL_DISCOVER, requestJson.toString(), callBack);
        } catch (Throwable e) {

            LogManager.e(Constant.TAG, "queryDiscover : ", e);

            XyUtil.doXycallBackResult(callBack);
        }

    }


    /**
     * 获取即将上映电影数据
     *
     * @param count    返回电影最大数量,0返回全部
     * @param version  当前版本号
     * @param callBack  index(0)为"0"请求成功
     *                  index(1)返回数据
     *                  {"status": 1,
     *                 "desc": "成功",
     *                 "body": {
     *                 "movieComming": [
     *                 {
     *                 "movieDetailPath":"http://channel.h5.komovie.cn/channelTest/movie?movieId=1075672",
     *                 "movieName": "少年梦",
     *                 "posterPath": "http: //service.bizport.cn/commerce/kmovie/poster/big/14748541474656.jpg"
     *                 }
     *                 ]
     *                 }
     *                 }
     */
    public static void queryCommingMovie(int count, String version, final SdkCallBack callBack) {
        JSONObject requestJson = new JSONObject();
        try {
            requestJson.put("count", count);
            requestJson.put("sdkVersion", NetUtil.APPVERSION);
            requestJson.put("channel", KeyManager.getAppKey());
            requestJson.put("version", version);
            NetWebUtil.sendPostRequest(NetWebUtil.WEB_SERVER_URL_COMMING_MOVIE, requestJson.toString(), callBack);
        } catch (Throwable e) {

            LogManager.e(Constant.TAG, "queryCommingMovie : ", e);

            XyUtil.doXycallBackResult(callBack);
        }
    }
}
/* SDK-682 chenrong 20161121 end*/